package com.aier.src.action;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.List;
import java.util.Map;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.aier.common.common.CommonSession;
import com.aier.user.common.UserExcleUtil;

@Scope("prototype")
@Component("appDownloadAction")
public class AppDownloadAction extends BaseAction {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    
    
    
    private ByteArrayInputStream inputExcel;
    private String filename;
    
    @Override
    @SuppressWarnings("unchecked")
    public String execute(){
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try {
            UserExcleUtil.createExcel((Map<String, List<Object>>) request.getSession()
                    .getAttribute(CommonSession.SESSION_SCHOOL_INFO)).write(out);
        } catch (IOException e) {
            return null;
        }catch(Exception e){
            e.printStackTrace();
        }
        inputExcel = new ByteArrayInputStream(out.toByteArray());
        filename="aier360.apk";
        return SUCCESS;
    }

    public ByteArrayInputStream getInputExcel() {
        return inputExcel;
    }

    public String getFilename() {
        return filename;
    }

}
